package com.asf.sofom.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.asf.sofom.domain.ODomicilios;

@Repository(value = "domiciliosDao")
public class JPADomicilios implements DomiciliosDao{
	

	private EntityManager em = null;
	
	@PersistenceContext
	public void setEntityManager(EntityManager em){
		this.em = em;
	}
	
	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")	
	public List<ODomicilios> getDomicilios() {
		TypedQuery<ODomicilios> tq = (TypedQuery<ODomicilios>) em.createNativeQuery("Select * from personas_domicilios", ODomicilios.class);
		List<ODomicilios> ld = tq.getResultList();
		return ld;
	}

	@Transactional(readOnly = false)
	public void setDomicilio(ODomicilios domicilio) {
		em.merge(domicilio);
	}

}
